import Vue from 'vue'
import Vuex from 'vuex'


Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    token: '',
    userId: '',
    userName: '',
    userNumber: '',
    userSex: '',
    userPhone: '',
    userEmail: '',
    userPicture: '',
    userWorkPosition: '',
    userAutoPush: '',
    permissions: '',
    //下拉机组 
    unitData: [],
    dropDownValue: [],
    jzjfxmArr: [],
    zjjfxmArr: [],
  },

  mutations: {
    bingLogin(state, data) {
      //改变登录状态
      state.token = data.data.JSESSIONID
      state.userId = data.data.id
      state.userName = data.data.name
      state.userNumber = data.data.number
      state.userSex = data.data.sex
      state.userPhone = data.data.phone
      state.userEmail = data.data.email
      state.userPicture = data.data.picture
      state.userWorkPosition = data.data.workPosition
      state.userAutoPush = data.data.autoPush
      state.picture = data.data.picture
      //将用户信息保存在本地
      uni.setStorage({ key: 'token', data: data.data.JSESSIONID })
      uni.setStorage({ key: 'userId', data: data.data.id })
      uni.setStorage({ key: 'userName', data: data.data.name })
      uni.setStorage({ key: 'userNumber', data: data.data.number })
      uni.setStorage({ key: 'userSex', data: data.data.sex })
      uni.setStorage({ key: 'userPhone', data: data.data.phone })
      uni.setStorage({ key: 'userEmail', data: data.data.email })
      uni.setStorage({ key: 'userPicture', data: data.data.picture })
      uni.setStorage({ key: 'userWorkPosition', data: data.data.workPosition })
      uni.setStorage({ key: 'userAutoPush', data: data.data.autoPush })
    },
    bingPermission(state, data) {
      //权限状态
      state.permissions = data

      //将用户信息保存在本地
      uni.setStorage({ key: 'permissions', data: data })
    },
    upData(state, data) {
      state[data.name] = data.data
    },
  }
})

export default store
